﻿Imports BUS, DTO
Public Class frmphieuthutienphat

    Private Sub frmphieuthutienphat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bus As New DocGiaBUS()
        Dim dsDG As New List(Of DocGiaDTO)
        dsDG = bus.LayDSDocGia()
        lue_HoTenDocGia.Properties.DataSource = dsDG
        lue_HoTenDocGia.Properties.ValueMember = "MaDocGia"
        lue_HoTenDocGia.Properties.DisplayMember = "TenDocGia"
        lue_HoTenDocGia.EditValue = 0

        Dim nhanvienBUS As New NhanVienBUS()
        Dim dsNV As New List(Of NhanVienDTO)
        dsNV = nhanvienBUS.LayDSNhanVien_ThuQuy()
        _LookUpEdit_NguoiThuTien.Properties.DataSource = dsNV
        _LookUpEdit_NguoiThuTien.Properties.ValueMember = "MaNhanVien"
        _LookUpEdit_NguoiThuTien.Properties.DisplayMember = "HoTen"
        _LookUpEdit_NguoiThuTien.EditValue = 0
    End Sub

    Private Sub lue_HoTenDocGia_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lue_HoTenDocGia.EditValueChanged
        Dim bus As New DocGiaBUS()
        _TextEdit_TienNo.Text = bus.LaySoTienNo(lue_HoTenDocGia.EditValue).ToString()
    End Sub

    Private Sub _TextEdit_SoTienThu_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _TextEdit_SoTienThu.EditValueChanged
    End Sub

    Private Sub _TextEdit_SoTienThu_EditValueChanging(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles _TextEdit_SoTienThu.EditValueChanging

    End Sub

    Private Sub _TextEdit_SoTienThu_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _TextEdit_SoTienThu.Leave
        If Integer.Parse(_TextEdit_SoTienThu.Text) > Integer.Parse(_TextEdit_TienNo.Text) Then
            MessageBox.Show("Tiền thu lớn hơn số tiền nợ !")
            _TextEdit_SoTienThu.Text = ""
            Return
        End If

        _TextEdit_SoTienConLai.Text = (Integer.Parse(_TextEdit_TienNo.Text) - Integer.Parse(_TextEdit_SoTienThu.Text)).ToString()

    End Sub

    Private Sub _SimpleButton_DongY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _SimpleButton_DongY.Click
        Dim sql As String = "insert into PHIEUTHUTIENPHAT(MaDocGia,SoTienThu,MaNhanVien)  Values (" + lue_HoTenDocGia.EditValue.ToString() + "," + _TextEdit_SoTienThu.Text + "," + _LookUpEdit_NguoiThuTien.EditValue.ToString() + " )"
        Dim bus As New DocGiaBUS()

        If bus.ThemPhieuThuTienPhat(sql) = 1 Then
            MessageBox.Show("Thêm phiếu thu thành công !")
        Else
            MessageBox.Show("Thêm phiếu thu thất bại !")
        End If
        Me.Close()
    End Sub
End Class